//
// 公告
//
<template>
  <div class="tenantMenu_main main_container">
    <div class="main_header">
      <div class="padding_container">
        <div class="right">
          <HeaderOperation :parent="this" />
        </div>
      </div>
    </div>
    <div v-loading="loading" class="main_main">
      <SearchBar :parent="this" />
      <div class="main_main_btn">
        <div class="main_btn_read" :class="{active : pageData.status == 2}" @click="btnClick(2)">
          <span>全部</span>
        </div>
        <div class="main_btn_unread" :class="{active : pageData.status == 0}" @click="btnClick(0)">
          <span v-if="notice !== ''">未读（{{ notice }}）</span>
          <span v-else>未读</span>
        </div>
        <div class="main_btn_unread" :class="{active : pageData.status == 1}" @click="btnClick(1)">
          <span>已读</span>
        </div>
      </div>
      <div ref="table_container" class="table_container">
        <el-table
          ref="table"
          :data="tableData"
          stripe
          border
          :height="tableHeight"
          :header-cell-style="messageStyle"
          :cell-class-name="cellClassName"
          :cell-style="cellStyle"
          :tree-props="{children: 'children', hasChildren: 'hasChildren'}"
          @cell-click="cellClick"
          @sort-change="(column)=>{sortChange(column, this)}"
          @selection-change="(val)=>{selectionChange(val, this)}"
        >
          <template slot="empty">
            <div class="empty_content">

              <el-image
                style="width: 120px; height: 100px; margin-left: calc(50% - 65px)"
                :src="imageUrl"
                :fit="fit"
              />
              <div>
                暂无公告
              </div>
            </div>
          </template>
          <el-table-column type="selection" width="70" align="center" />
          <el-table-column
            :show-overflow-tooltip="true"
            label="公告标题"
            min-width="300"
            prop="content"
          >
            <template slot-scope="scope">
              <div class="message_content">
                <div v-if="scope.row.statusName=='未读'" class="viewed_content" />
                <div v-else class="viewed_content2" />
                <div class="viewed_content3">{{ scope.row.content }}</div>
              </div>
              <!--              <div>{{ scope.row.content }}</div>-->
            </template>
          </el-table-column>
          <el-table-column
            :show-overflow-tooltip="true"
            label="公告类型"
            min-width="100"
          >
            <template slot-scope="scope">
              <div class="message_content">
                <!--                <div v-if="scope.row.statusName=='未读'" class="viewed_content" />-->
                <!--                <div v-else class="viewed_content2" />-->
                <div>{{ scope.row.title }}</div>
              </div>
            </template>
          </el-table-column>
          <Column
            v-for="(column,index) in tableColumns"
            :key="index"
            :prop="column.prop"
            :is-show="column.isShow"
            :label="column.label"
            :sortable="column.sortable"
            :width="column.width"
            :min-width="column.minWidth"
            :align="column.align"
          />
          <el-table-column label="操作" align="center" fixed="right" width="180">
            <template slot-scope="scope">
              <el-button
                type="text"
                @click.stop="deleteOne(scope.row)"
              >删除</el-button>
            </template>
          </el-table-column>
        </el-table>
      </div>
    </div>
    <div class="main_bottom">
      <pagination
        :total="total"
        :page.sync="pageData.pageNum"
        :limit.sync="pageData.pageSize"
        :selected-num="selectionsAll.length"
        @pagination="getList"
      />
    </div>

  </div>
</template>

<script>
import imageUrl from '@/assets/images/backlogTask/消息暂无数据.jpg'
import { listForSaleCollect, messageEmptyV2, deleteV2 } from '@/api/backlogTask/backlogTask'
import { getMsgNum } from '@/api/backlogTask/backlogTask'
import { mapGetters } from 'vuex'
import ShowDetailOld from '../../system/notice/showDetail'
import ShowSystemDetailOld from '../../superManage/reportForm/superNotice/showDetail'
export default {
  name: 'ByMaterial',
  computed: {
    ...mapGetters([
      'notificationChangeTag', 'userId'
    ])
  },
  watch: {
    notificationChangeTag() {
      this.getList()
    }
  },
  data() {
    return {
      imageUrl: imageUrl,
      loading: true,
      pageId: '公告', // 页面唯一标识
      isGetList: '1', // 表示一进页面不需要调list方法
      pageData: {
        pageNum: 1,
        pageSize: 20,
        orderByColumn: 'sendTime',
        isAsc: 'desc',
        type: '2',
        status: 2
      },
      // tableKey: 1,
      total: 1, // 数据一共有多少条
      mainId: 'id', // 表格行ID
      tableHeight: '0', // 表格高度
      tableData: [], // 表格数据
      tableColumns: [], // 表格实际用的字段
      searchColumns: [], // 搜索区实际用的字段
      selections: [], // 表格当前页所选中的行
      selectionsAll: [], // 表格所有页选中的行
      defaultTableColumns: [// 表格常规字段（初始值）
        // { prop: 'title', label: '公告类型', canOrder: false },
        // { prop: 'title', label: '公告类型', canOrder: false },
        { prop: 'userName', label: '发送人员', canOrder: false },
        { prop: 'sendTime', label: '发送时间', sortable: 'custom', canOrder: false }
      ],
      defaultSearchColumns: [// 搜索区常规字段（初始值）
        // { prop: 'status', label: '状态', type: 'select', optionsName: 'statusOptions', hasDefault: true, defaultKey: 'statusDefault' },
        { prop: 'title', label: '公告类型', type: 'select', optionsName: 'statusOptions1' },
        { prop: 'sendTime', label: '发送时间', type: 'time' }
      ],
      operationData: [ // 右上角的操作按钮
        { label: '标记已读2', perm: '' }
      ],
      statusOptions: [ // 选择组件数据源
        { value: undefined, label: '全部' },
        { value: 1, label: '已读' },
        { value: 0, label: '未读' }
      ],
      statusOptions1: [
        { value: undefined, label: '全部' },
        { value: '系统公告', label: '系统公告' },
        { value: '企业公告', label: '企业公告' }
      ],
      Updata: [],
      orderTime: '',
      notice: '',
      itenindex: 1,
      statusDefault: 0
    }
  },
  created() {
  },
  mounted() {
  },
  methods: {
    cellClassName(row) {
      if (row.column.property == 'content' && row.row.statusName == '未读') {
        return 'overstriking'
      }
    },
    btnClick(index) {
      this.pageData.status = index
      this.getList()
    },
    messageStyle({ row, column, rowIndex, columnIndex }) {
      if (rowIndex === 0 && columnIndex == 1) { // 指定坐标
        return {
          padding: '0 20px'
        }
      } else {
        return ''
      }
    },
    cellStyle({ row, column }) {
      if (column.property == 'content') {
        return {
          cursor: 'pointer',
          color: '#387bfc'
        }
      }
    },
    cellClick(row, column, cell) {
      if (column.property == 'content') {
        messageEmptyV2({ ids: row.id }).then(res => {
          if (row.title == '企业公告') {
            this.$layer.iframe({// 弹框
              content: {
                content: ShowDetailOld, // 传递的组件对象
                parent: this, // 当前的vue对象
                data: {
                  id: row.contentId
                }// props
              },
              area: ['880px', '820px'],
              title: '公告详情', // 标题
              shadeClose: false // 点击遮罩是否关闭
            })
          } else {
            this.$layer.iframe({// 弹框
              content: {
                content: ShowSystemDetailOld, // 传递的组件对象
                parent: this, // 当前的vue对象
                data: {
                  id: row.contentId
                }// props
              },
              area: ['880px', '820px'],
              title: '查看系统公告', // 标题
              shadeClose: false // 点击遮罩是否关闭
            })
          }
        })
      }
      this.getList()
    },
    /**
     * 极联云耀生产管理系统V1.0
     * 模块名称：销售管理
     */
    getList() {
      listForSaleCollect(this.pageData).then(res => {
        this.tableData = res.data
        this.total = res.total
        this.loading = false
        this.$nextTick(() => {
          this.setSelectRow(this)// 设置行选中
          this.tableHeight = this.$refs.table_container.offsetHeight
        })
      })
      getMsgNum(this.userId).then(res => {
        this.notice = res.data.notice.num
        if (this.notice == '0') {
          this.notice = ''
        }
      })
    },
    getExportData(data) {
      return new Promise(function(resolve, reject) {
        listForSaleCollect(data).then(res => {
          resolve(res.data.dataTable.data)
        })
      })
    },
    deleteOne(row) {
      const _this = this
      this.$confirm('确定要删除吗', '删除确认', {
        confirmButtonText: '确定',
        cancelButtonText: '取消', cancelButtonClass: 'cancelConfirm',
        type: 'warning'
      }).then(function() {
        deleteV2(row[_this.mainId]).then(res => {
          _this.$message({
            message: res.msg,
            type: 'success'
          })
          _this.selectionsAll = []
          _this.getList()
        })
      }).catch(() => {})
    }
  }
}
</script>

<style lang="less" scoped>
/deep/.overstriking {
  font-weight: 700 !important;
}
.table_container {
  margin-top: 10px !important;
}
.active {
  height: 100% !important;
  background: rgba(56, 123, 253, 1) !important;
  color: #fff !important;
  border: none !important;
  font-size: 14px !important;
}
.main_main_btn {
  display: flex;
  height: 30px;
  width: 100%;
  padding-left: 29px;
  margin-top: 20px;
  .main_btn_read {
    width: 85px;
    height: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    border: 1px solid rgba(228, 228, 228, 1);
    border-radius:4px 0px 0px 4px;
    font-size: 14px;
    color: #999999;
    cursor: pointer
  }
  .main_btn_unread:nth-of-type(2) {
    border-radius:0px 0px 0px 0px !important;
  }
  .main_btn_unread {
    width: 85px;
    height: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    border: 1px solid rgba(228, 228, 228, 1);
    border-left: none;
    border-radius:0px 4px 4px 0px;
    font-size: 14px;
    cursor: pointer;
    color: #999999;
  }
}
.message_content{
  display: flex;
  line-height: 30px;
  .viewed_content{
    width: 8px;
    height: 8px;
    background-color: #FA6B6D;
    border-radius: 50%;
    margin-top: 10px;
    margin-right: 10px;
  }
  .viewed_content2{
    width: 8px;
    height: 8px;
    border-radius: 50%;
    margin-top: 10px;
    margin-right: 10px;
  }
  .viewed_content3 {
    overflow: hidden;
    text-overflow:ellipsis;
    white-space: nowrap;
  }
}
.empty_content{
  text-align: center;
}
.main_header{
  .padding_container{
    justify-content: flex-end;
  }
}
</style>
